package com.shelpe.services.tenant.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class FileProcess {
	
	public static List<String> readFileByLines(String fileName){
		
		File file = new File(fileName);      
		BufferedReader reader = null;
		List<String> result = new ArrayList<String>();
		
		try{  
			
			reader = new BufferedReader(new FileReader(file));  
			String line = null;  	                      
	         
			while((line = reader.readLine()) != null){  
				result.add(line);
			}  
			
			reader.close();  
	       
		}catch(IOException e){    
			e.printStackTrace();  
			
		}finally{  	        
			if(reader != null){  
				try{      
					reader.close();             
				}catch(IOException e1){            
				}   
			}     
		}  
		
		return result;
	}
	
	public static void appendToFile(String fileName, String line){

		try{         
			FileWriter writer = new FileWriter(fileName, true);         
			writer.write(line);        
			writer.close();     
			
		}catch(IOException e){        
			e.printStackTrace();  
		}  
	}

}
